from urllib.parse import urlparse

import requests
from feapder.utils.tools import urldecode
from logg import  gen_header
from requests import Response


class BossSpider():
    _boss_stoken = ''
    def __init__(self):
        self.reset_session()
    def reset_session(self):
        self.session = requests.session()
        self.session.verify = False
        proxy = ''
        self.session.proxies = {
            'http':'http://' + proxy,
            'https':'http://' + proxy,
        }
        self.session.headers = gen_header("""accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9
cache-control: no-cache
pragma: no-cache
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: same-origin
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36""")

    def get_update_stoken(self, uri: str) -> Response:
        res = self.session.get(uri)
        if 'seed' in res.url:
            returnUri = urlparse(res.url)

            query = urldecode(returnUri.query)
            seed = query.get('seed')
            name = query.get('name')
            ts = query.get('ts')

    def run(self):
        uri = 'https://www.zhipin.com/c101010100-p100101/'
        self.get_update_stoken(uri)


if __name__ == '__main__':
    b = BossSpider()
    b.run()